package com.forekenow.oop;

/**
 * 对象数组：数组中可以存对象
 */
public class ObjectArray {

    public void getAllMessage(Student[] array){
        for (Student ss: array) {
            System.out.println(ss.getName()+"----"+ss.getAge());
        }
    }

    public Student[] getAll(){
        Student[] array = new Student[2];
        Student s1 = new Student();
        s1.setName("tom");
        s1.setAge(23);
        Student s2 = new Student();
        s2.setAge(30);
        s2.setName("fender");

        //3.将对象保存到数组中
        array[0] = s1;
        array[1] = s2;
        return array;
    }

    public static void main(String[] args) {
        //创建ObjectArray对象
        ObjectArray objectArray = new ObjectArray();
        Student[] sss = objectArray.getAll();
        //调用ObjectArray对象的方法
        objectArray.getAllMessage(sss);

    }
}
